home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / libfpvm / WIN32 / Pvmfstartpvmd.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  4KB  |  122 lines

  1.  
  2. /* $Id: Pvmfstartpvmd.c,v 1.1 1997/06/27 16:34:39 pvmsrc Exp $ */
  3.  
  4. #ifdef WIN32
  5. #include "..\..\src\pvmwin.h"
  6. #endif
  7.  
  8. #include <stdio.h>
  9. #include "pvm3.h"
  10. #include "pvm_consts.h"
  11. #include "pvmalloc.h"
  12.  
  13. void __fortran
  14. PVMFSTARTPVMD (args_ptr, block, info, args_len)
  15. char * args_ptr; int args_len;
  16. int *block;
  17. int *info;
  18. {
  19.     char *nargs;            /* args (null terminated) */
  20.     int ac = 0;                /* # of agruments initialize to 0 */
  21.     char **av;                /* argument vector */
  22.     register char *ch;            /* temp char pointer */
  23.     register char *beg;            /* pointer to begining of word */
  24.     register char *end;            /* pointer to end of word */
  25.     register int len;            /* length of word */
  26.     register int i;            /* loop index */
  27.  
  28. #if ( DEBUG )
  29.     /* printout incoming nargs */
  30.     printf( "%d \"%s\"\n", args_len, args_ptr );
  31. #endif
  32.     /* Some Fortran compilers allow for strings of zero length */
  33.     if ( args_len == 0 ) {    /* null args */
  34.     av = (char **)0;        /* make av a null pointer */
  35.     goto pvmd;
  36.     } else {                /* something in args */
  37.     if ( ( nargs = TALLOC( args_len + 1, char, "nargs" ) )
  38.         == NULL ) {
  39.         pvmlogerror("pvmfstartpvmd() can't get memory\n");
  40.         goto bail;
  41.     }
  42.     /* copy args (ftocptr() could have been used for that) */
  43.     strncpy( nargs, args_ptr, args_len );
  44.     nargs[args_len] = '\0'; /* terminate with null */
  45.     }
  46.     ch = nargs;                /* pointer at the begining of nargs */
  47.     /* assume a max of 32 args (8 should be OK from pvmd3(3PVM)) */
  48.     if ( ( av = TALLOC( 32, char *, "av" ) ) == NULL ) {
  49.     pvmlogerror("pvmfstartpvmd() can't get memory\n");
  50.     PVM_FREE( nargs );        /* avoid memory leeks */
  51.     goto bail;
  52.     }
  53.     /* at this point nargs contain at least 1 char */
  54.     for ( ; ; ) {
  55.     /* move forward until no space nor tab */
  56.     for( ; *ch == ' ' || *ch == '\t'; ch++ );
  57.     beg = ch;            /* that's the begining of a word */
  58.     /* move forward until space, tab or null */
  59.     for( ; *ch != ' ' && *ch != '\t' && *ch != '\0'; ch++ );
  60.     end = ch;            /* that's the end of a word */
  61.     len = end - beg;        /* length of the word */
  62.     /* if nothing else then space, tab or null has been found */
  63.     /* then end of nargs is reached (exit point of loop) */
  64.     if ( len == 0 ) break;
  65.     /* allocate memory for word in agument vector */
  66.     if ( ( av[ac] = TALLOC( len + 1, char, "av[ac]" ) ) == NULL ) {
  67.         pvmlogerror("pvmfstartpvmd() can't get memory\n");
  68.         PVM_FREE( nargs );        /* avoid memory leeks */
  69.         for ( i = 0; i < ac; i++ )
  70.         PVM_FREE( av[i] );
  71.         goto bail;
  72.     }
  73.     strncpy( av[ac], beg, len );    /* copy word to arg vector */
  74.     *( av[ac] + len ) = '\0';    /* null terminate word */
  75.     ac++;                /* increment arg counter */
  76.     }
  77. #if ( DEBUG )
  78.     printf( "ac is %d\n", ac );
  79. #endif
  80.     if ( ac == 0 ) {
  81.     /* no args found */
  82.     PVM_FREE( av );            /* free allocated memory */
  83.     av = (char **)0;        /* make av a NULL pointer */
  84. #if ( DEBUG )
  85.     } else {
  86.     /* printout result */
  87.     for ( i = 0; i < ac; i++ )
  88.         printf( "av[%2d] is \"%s\"\n", i, av[i] );
  89. #endif
  90.     }
  91.     PVM_FREE( nargs );            /* free allocated memory */
  92.  pvmd:
  93.     /* hopefully pvm_start_pvmd is freeing allocated mem for av */
  94.     *info = pvm_start_pvmd( ac, av, *block );
  95.     return;
  96.  bail:
  97.     *info = -1;
  98.     return;
  99. }
  100.  
  101. /*
  102.  *----------------------------------------------------------------------
  103.  * RCS identification
  104.  *----------------------------------------------------------------------
  105.  * $Author: pvmsrc $
  106.  * $Date: 1997/06/27 16:34:39 $
  107.  * $Locker:  $
  108.  * $Revision: 1.1 $
  109.  * $Source: /home/nova/u3/pvmsrc/.CVS/PVM/pvm3.4/libfpvm/WIN32/Pvmfstartpvmd.c,v $
  110.  * $State: Exp $
  111.  *----------------------------------------------------------------------
  112.  * For GNU Emacs:
  113.  *----------------------------------------------------------------------
  114.  * Local Variables:
  115.  * mode: C
  116.  * abbrev-mode: t
  117.  * comment-column: 40
  118.  * version-control: t
  119.  * End:
  120.  *----------------------------------------------------------------------
  121.  */
  122.